classdef BodyCoordSpecVelUpd < matlab.System & matlab.system.mixin.Propagates ...
        & matlab.system.mixin.CustomIcon & matlab.system.mixin.Nondirect
    % BodyCoordSpecVelUpd 体坐标系下比速度更新解算周期
    %
    % NOTE: When renaming the class name BodyCoordSpecVelUpd, the file name
    % and constructor name must be updated to use the class name.
    %
    % This template includes most, but not all, possible properties, attributes,
    % and methods that you can implement for a System object in Simulink.
    % 说明可参考bodycoordspecvelupdstep函数 TODO: 增加类说明
    
    % NOTE: 下述函数可以有不同实现：dvScul_l_2ndod, DvRot_m_exactform_5thod
    
    % Public, tunable properties
    properties
        
    end
    
    % Public, non-tunable properties
    properties(Nontunable)
        
    end
    
    properties(DiscreteState)
        DS_upsilon_l
        DS_DvScul_l
        DS_upsilon_l1
        DS_DvScul_l1
    end
    
    % Pre-computed constants
    properties(Access = private)
        
    end
    
    methods
        % Constructor
        function obj = BodyCoordSpecVelUpd(varargin)
            % Support name-value pair arguments when constructing object
            setProperties(obj,nargin,varargin{:})
        end
        
        function [DvSFB_m1_m] = step_ns(obj, alpha_m, DvScul_m_ext)
            % 运行中速解算步骤
            DvRot_m = DvRot_m_exactform_5thod(obj.DS_upsilon_l, alpha_m); % REF1式8.59
            if isempty(DvScul_m_ext) || any(isnan(DvScul_m_ext))
                DvSFB_m1_m = obj.DS_upsilon_l + DvRot_m + obj.DS_DvScul_l; % REF1式8.56
            else
                DvSFB_m1_m = obj.DS_upsilon_l + DvRot_m + DvScul_m_ext;
            end
        end
    end
    
    methods(Access = protected)
        %% Common functions
        function setupImpl(obj)
            % Perform one-time calculations, such as computing constants
        end
        
        function resetImpl(obj)
            % Initialize / reset discrete-state properties
            obj.DS_upsilon_l = zeros(3, 1);
            obj.DS_DvScul_l = zeros(3, 1);
            obj.DS_upsilon_l1 = NaN(3, 1);
            obj.DS_DvScul_l1 = NaN(3, 1);
        end
        
        %% Backup/restore functions
        function s = saveObjectImpl(obj)
            % Set properties in structure s to values in object obj
            
            % Set public properties and states
            s = saveObjectImpl@matlab.System(obj);
            
            % Set private and protected properties
            %s.myproperty = obj.myproperty;
        end
        
        function loadObjectImpl(obj,s,wasLocked)
            % Set properties in object obj to values in structure s
            
            % Set private and protected properties
            % obj.myproperty = s.myproperty;
            
            % Set public properties and states
            loadObjectImpl@matlab.System(obj,s,wasLocked);
        end
        
        %% Simulink functions
        function ds = getDiscreteStateImpl(obj)
            % Return structure of properties with DiscreteState attribute
            ds = struct([]);
        end
        
        function flag = isInputSizeMutableImpl(obj,index)
            % Return false if input size cannot change
            % between calls to the System object
            flag = false;
        end
        
        function out = getOutputSizeImpl(obj)
            % Return size for each output port
            out = [1 1];
            
            % Example: inherit size from first input port
            % out = propagatedInputSize(obj,1);
        end
        
        function updateImpl(obj, Dupsilon_lx, alpha_l1, Dalpha_lx)
            % Update discrete states as a function of input u
            % 运行高速解算步骤
            obj.DS_upsilon_l1 = obj.DS_upsilon_l;
            obj.DS_DvScul_l1 = obj.DS_DvScul_l;
            [obj.DS_DvScul_l, obj.DS_upsilon_l] = vel_hs(obj.DS_DvScul_l1, obj.DS_upsilon_l1,...
                Dupsilon_lx, alpha_l1, Dalpha_lx, @dvScul_l_2ndod);
        end
        
        function [upsilon_l, upsilon_l1, DvScul_l, DvScul_l1] = outputImpl(obj, Dupsilon_lx, alpha_l1, Dalpha_lx)
            % Calculate output y as a function of discrete states and
            % direct feedthrough inputs
            upsilon_l = obj.DS_upsilon_l;
            upsilon_l1 = obj.DS_upsilon_l1;
            DvScul_l = obj.DS_DvScul_l;
            DvScul_l1 = obj.DS_DvScul_l1;
        end
        
        function icon = getIconImpl(obj)
            % Define icon for System block
            icon = mfilename("class"); % Use class name
            % icon = "My System"; % Example: text icon
            % icon = ["My","System"]; % Example: multi-line text icon
            % icon = matlab.system.display.Icon("myicon.jpg"); % Example: image file icon
        end
    end
    
    methods(Static, Access = protected)
        %% Simulink customization functions
        function header = getHeaderImpl
            % Define header panel for System block dialog
            header = matlab.system.display.Header(mfilename("class"));
        end
        
        function group = getPropertyGroupsImpl
            % Define property section(s) for System block dialog
            group = matlab.system.display.Section(mfilename("class"));
        end
    end
end
